package edu.egypt.servlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collection;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.sun.org.apache.bcel.internal.generic.Type;

import edu.egypt.helpers.RoleDbOperations;
import edu.egypt.model.Permission;

/**
 * Servlet implementation class Demo
 */
public class UpdateRoleServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public UpdateRoleServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String Json = request.getParameter("data");
		int id = Integer.parseInt(request.getParameter("id"));
		System.out.println(Json);
		ArrayList<Permission> allperm = new ArrayList<>();
		Gson g = new Gson();
		
		java.lang.reflect.Type token = new TypeToken<ArrayList<Permission>>() {}.getType();
		allperm = g.fromJson(Json, token);
		
		RoleDbOperations.getSingletonInstance().UpdateRolePerm(allperm, id);
		
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
	}

}
